package com.synnex.mobile.servier.web.calendar.controller.mobile;

import com.synnex.mobile.generic.core.exception.SystemException;
import com.synnex.mobile.generic.core.json.JSONModel;
import com.synnex.mobile.generic.log.dao.annotation.LogClass;
import com.synnex.mobile.generic.log.dao.annotation.LogMethod;
import com.synnex.mobile.generic.web.anotation.mapping.RequestMapping;
import com.synnex.mobile.generic.web.view.ModelAndView;
import com.synnex.mobile.servier.core.calendar.bo.CalendarBo;
import com.synnex.mobile.servier.web.calendar.controller.AbstractCalendarController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: kerryf
 * Date: 13-8-6
 * To change this template use File | Settings | File Templates.
 */
@LogClass(name="mobile calendar")
@RequestMapping(url="/mobile/agenda")
public class MobileCalendarController extends AbstractCalendarController {

    private static  String[] EXCLUDE_PROPERTIES = new String[]{"updateDate","entryDate","id"};
    @LogMethod(name="list calendar")
    @RequestMapping(url="/timeList.do")
      public ModelAndView listCalendar(HttpServletRequest request,HttpServletResponse response){

          JSONModel jsonModel = JSONModel.create().setExcludes(EXCLUDE_PROPERTIES);
          Map<String,Object> model = new HashMap<String,Object>();
        String link="http://"+this.getConfig().getFtpHost()+this.getConfig().getFtpDownLoadPath()+"/";
          try {
              List<CalendarBo> data = calendarService.listCalendar(null);
              model.put("totalCount", data.size());
              model.put("results",data);
              model.put("link",link);

              jsonModel.setData(model)  ;
              return createJSONModelAndView(jsonModel);
          } catch (Exception e) {
              throw  new SystemException(e);
          }
      }
}
